<?php
// +----------------------------------------------------------------------
// | ZGUAN [ 致力于帮助更多的中小企业物联网转型 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2024 https://www.zguan.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ZGUAN 并不是自由软件，未经许可不能去掉ZGUAN 相关版权
// +----------------------------------------------------------------------
// | Author: ZGUAN Team <admin@zguan.cn>  400-611-6696  15899929162
// +----------------------------------------------------------------------
namespace app\common\dao\housing;

use app\common\dao\BaseDao;
use app\common\model\housing\HousingResourceLabelModel;

class HousingResourceLabelDao extends BaseDao
{

    /**
     * @return HousingResourceLabelModel
     */
    protected function getModel(): string
    {
        return HousingResourceLabelModel::class;
    }

    public function search(array $where, int $propertyId = null)
    {
        return $this->getModel()::getDB()
            ->when($propertyId !== null, function ($query) use ($propertyId) {
                $query->where('property_id', $propertyId);
            })
            ->when(isset($where['label_id']) && $where['label_id'] !== '', function ($query) use ($where) {
                $query->where('label_id', intval($where['label_id']));
            })
            ->when(isset($where['resource_id']) && $where['resource_id'] !== '', function ($query) use ($where) {
                $query->where('resource_id', intval($where['resource_id']));
            });
    }

    /**
     *  根据房间 ID 删除标签
     * @param int $roomId
     * @return bool
     *
     * @author Amos
     * 2024-06-03 19:52
     */
    public function delByHousingId(int $housingId)
    {
        return $this->getSearch([
            'housing_id' => $housingId
        ])->delete();
    }

}